package wineshop.service.customer;

import java.util.Properties;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import org.junit.After;
import org.junit.Before;

import wineshop.test.TestDataBeanRemote;

public abstract class AbstractEJBTest {
	protected InitialContext context;

	@Before
	public void setUp() throws NamingException {
		Properties prop = new Properties();

		// We need to tell the context where and how to look
		prop.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory");
		prop.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
		prop.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");

		// Should not be necessary for local test (default values), but
		// currently is
		prop.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
		prop.setProperty("org.omg.CORBA.ORBInitialPort", "3700");

		context = new InitialContext(prop);

		TestDataBeanRemote testDataBean = (TestDataBeanRemote) context.lookup("wineshop.test.TestDataBeanRemote");
		testDataBean.cleanData();
		testDataBean.initData();
	}

	@After
	public void tearDown() throws NamingException {
		context.close();
		context = null;
	}
}
